package com.exam;

import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.*;
import java.nio.Buffer;
import java.util.Map;
import java.util.Properties;

public class FileTest {
    public static void main(String[] args) throws IOException, DocumentException {
//        InputStream is = new FileInputStream("D:\\eclipse\\demo\\user.properties");
//        BufferedInputStream bs = new BufferedInputStream(is);
//        Properties test = new Properties();
//        test.load(bs);
//        System.out.println(test instanceof Map);
//        for(String i:test.stringPropertyNames()){
//            System.out.println(test.getProperty(i));
//        }
//        for(Map.Entry<Object, Object> entry : test.entrySet()){
//            System.out.println(entry.getKey() + "-->" + entry.getValue());
//            test.setProperty((String)entry.getKey(), (String)entry.getValue());
//        }
//        BufferedWriter bufferedWriter= new BufferedWriter(new FileWriter("D:\\eclipse\\demo\\user.properties", true));
//        test.store(bufferedWriter, "测试");
        FileInputStream is = new FileInputStream("D:\\eclipse\\demo\\helloworld.xml");
        SAXReader sax = new SAXReader();
        Document test1 = sax.read(is);
        Element user = test1.getRootElement();
        Element element = user.element("user");
        System.out.println(element.elementText("name"));
        for(Element ele : element.elements()){
            System.out.println(ele.getText());
            System.out.println(ele.getName());
            System.out.println(ele.getStringValue());
        }



    }
}
